package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.minimall.MallUserWithdrawalsRecord;
import com.sc.nft.entity.vo.WxMiniUserWithdrawalsVO;
import com.sc.nft.entity.vo.mall.MallUserWithdrawalsRecordAdminPage;
import com.sc.nft.enums.WithdrawalsStatusEnum;
import com.sc.nft.mapper.MallUserWithdrawalsRecordMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
 * <p>
 * 用户提现记录表 DAO
 * </p>
 *
 * @author author
 * @since 2024-05-20
 */
@Slf4j
@Repository
public class MallUserWithdrawalsRecordDao extends ServiceImpl<MallUserWithdrawalsRecordMapper, MallUserWithdrawalsRecord> {

    public Page<MallUserWithdrawalsRecordAdminPage> getAdminPage(Date startTime, Date endTime, String userTel,
                                                                 WithdrawalsStatusEnum withdrawalsStatus, Integer pageNo, Integer pageSize) {
        return baseMapper.getAdminPage(new Page<>(pageNo, pageSize), startTime, endTime, userTel, withdrawalsStatus);
    }

    /**
     * 获取用户提现记录
     *
     * @param wxMiniUserId
     * @param pageNo
     * @param pageSize
     * @return
     */
    public Page<WxMiniUserWithdrawalsVO> getUserWithdrawalsRecord(Long wxMiniUserId, Integer pageNo, Integer pageSize) {
        return baseMapper.getUserWithdrawalsRecord(new Page<>(pageNo, pageSize), wxMiniUserId);
    }

    public Boolean turnDown(Long id, Long auditAdminUserId, Date auditTime, String auditRemark) {
        LambdaUpdateWrapper<MallUserWithdrawalsRecord> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(MallUserWithdrawalsRecord::getId, id);
        wrapper.set(MallUserWithdrawalsRecord::getAuditAdminUserId, auditAdminUserId);
        wrapper.set(MallUserWithdrawalsRecord::getAuditTime, auditTime);
        wrapper.set(MallUserWithdrawalsRecord::getNote, auditRemark);
        wrapper.set(MallUserWithdrawalsRecord::getWithdrawalsStatus, WithdrawalsStatusEnum.REFUSE_TO_WITHDRAW);
        return update(wrapper);
    }

    /**
     * 审核通过
     *
     * @param id
     * @param auditAdminUserId
     * @param auditTime
     * @param auditRemark
     * @return
     */
    public Boolean pass(Long id, Long auditAdminUserId, Date auditTime, String auditRemark, String outBatchNo) {
        LambdaUpdateWrapper<MallUserWithdrawalsRecord> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(MallUserWithdrawalsRecord::getId, id);
        wrapper.set(MallUserWithdrawalsRecord::getAuditAdminUserId, auditAdminUserId);
        wrapper.set(MallUserWithdrawalsRecord::getAuditTime, auditTime);
        wrapper.set(MallUserWithdrawalsRecord::getNote, auditRemark);
        wrapper.set(MallUserWithdrawalsRecord::getOutBatchNo, outBatchNo);
        wrapper.set(MallUserWithdrawalsRecord::getWithdrawalsStatus, WithdrawalsStatusEnum.WITHDRAWING);
        return update(wrapper);
    }
}
